package org.exhaust.framework.net.test.protocol.server.udp.handler;

import io.netty.channel.ChannelHandlerContext;
import org.exhaust.framework.net.common.protocol.BaseUdpFrame;
import org.exhaust.framework.net.common.protocol.handler.BusinessDataHandler;
import org.exhaust.framework.net.test.protocol.server.udp.client.HelloMsg;

public class ClientMsgBusinessDataHandler extends BusinessDataHandler<BaseUdpFrame> {
    @Override
    public void handleMsg(ChannelHandlerContext ctx, BaseUdpFrame packet) {
        if (packet.getFrame() instanceof HelloMsg) {
            final HelloMsg helloFrame = (HelloMsg) packet.getFrame();
            System.out.println("hello msg:" + helloFrame.getMsg());
            BaseUdpFrame frame = new BaseUdpFrame(helloFrame);
            frame.setRecipient(packet.getSender());
            frame.setSender(packet.getRecipient());
            ctx.channel().writeAndFlush(frame);
        }
    }
}
